package com.wiscamp.ninechapters.ddd;

import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.Collection;

@Setter
@Getter
public class PagedEntities<T> implements DataTransferObject {

    private int page = 0;

    private int pages = 0;

    private int totalCount = 0;

    private int pageSize = 0;

    private String sortDirection = "";

    private String sortProperty = "";

    public int getPages() {
        if (totalCount > 0 && pageSize > 0) {
            int reminder = totalCount % pageSize;
            if (reminder == 0)
                pages = totalCount / pageSize;
            else
                pages = (totalCount / pageSize) + 1;
        }
        return pages;
    }


    private Collection<T> entities = new ArrayList<>();

    public PagedEntities(int totalCount, int pageSize, Collection<T> entities, int page, String sortDirection, String sortProperty) {
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        this.entities.addAll(entities);
        this.setPage(page);
        this.setSortDirection(sortDirection);
        this.setSortProperty(sortProperty);
    }

}
